<template>
    <Layout>

        <Form ref="form1" :model="form1" :label-width="120">
            <Row  class="query-form" style="padding-top: 15px">
                <Col span="8">
                    <FormItem label='会议名称：'>
                        <Input  type='text' v-model='form1.noticName'></Input>
                    </FormItem>
                </Col>
                <Col span="8">

                </Col>
                <Col span="8" >
                    <Button @click="reset" class="ivu-btn-reset"  >重置</Button>
                    <Button  class="ivu-btn-query"   icon="md-search"  @click="query">查询</Button>
                </Col>
            </Row>
        </Form>

        <Table ref='table' :height="tableHeight"  no-data-text="没有查询到相关数据！" :loading="buttonLoading" size="small"
               border :columns="columns1"  :data="dataTable">
        </Table>

        <Row style="margin-right:10px;">
            <Col span="24" >
                <Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray" show-total show-sizer show-elevator />
            </Col>
        </Row>
    </layout>
</template>

<script>
    import {Api} from '@/api/index.js'
    import {sessionStorage} from '@/common/cacheUtils.js';
    export default {
        components:{
        },
        data() {
            return {
                createUserId:'',
                form1: {
                },
                form2: {
                    members:'',
                    membersId:''
                },
                //分页参数
                pageSizeArray: [10, 20, 50],
                pagedata: {
                    total: 0,
                    pageSize: 10,
                    currentPage: 1,
                },

                columns1: [
                    {
                        title: "序号",
                        width: 80,
                        align: "center",
                        fixed: 'left',
                        render: (h, params) => {
                            return h('span', params.index + (this.pagedata.currentPage - 1) * this.pagedata.pageSize + 1);
                        }
                    },
                    { key:'noticName',title: '会议名称',  align: 'center' },
                    { key:'noticDate',title: '会议时间',  align: 'center' ,
                        render: (h, params) => {
                            if (params.row.startDate != null&&params.row.endDate != null){
                                let startDate = new Date(params.row.startDate);
                                let endDate = new Date(params.row.endDate);
                                return h('span', startDate.getFullYear() + '/' + (startDate.getMonth() + 1) + '/' + startDate.getDate() + ' ~ ' +
                                    endDate.getFullYear() + '/' + (endDate.getMonth() + 1) + '/' + endDate.getDate())
                            }
                            return h('span', "")
                        }},
                    { key:'noticAddress',title: '会议地点',  align: 'center' },
                    { key:'noticDesc',title: '会议内容',  align: 'center' },

                    {
                        title: '操作',
                        key: 'action',
                        fixed: 'right',
                        minWidth: 100,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('A', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '12px',
                                    },
                                    on: {
                                        click: () => {
                                            this.save(params.row);
                                        }
                                    }
                                }, '选择'),
                            ]);
                        }
                    }
                ],
                buttonLoading:false,tableHeight : 450,
                dataTable : [],
                switchFlag:false
            }
        },
        mounted: function() {
            this.tableHeight =window.innerHeight - 420;
            this.createUserId = JSON.parse(sessionStorage('paramUserInfo').get('userInfo'))["createUserId"]
            this.query();
        },
        methods: {
            pageChange(pageNum) {
                this.pagedata.currentPage = pageNum;
                this.query();
            },
            pageSizeChange(pageSize) {
                this.pagedata.pageSize = pageSize;
                this.query();
            },

            copyArray(arr) {
                return JSON.parse(JSON.stringify(arr));
            },


            save(row){
                this.$emit('selectMission',row);

            },

            closeModal(){
                this.$emit('closeModal1');
            },

            query() {this.buttonLoading=true
                let companyId = sessionStorage('userId').getObject('userId').companyId;
                let data = {
                    startPage: this.pagedata.currentPage,
                    size: this.pagedata.pageSize,
                    orgId:companyId
                };

                data = Object.assign(data, JSON.parse(JSON.stringify(this.form1)));
                let url = Api.queryMeetingNoticReceipt;
                this.$http.get(url, {params: data}).then((res) => {
                    this.buttonLoading =false;
                    this.dataTable = res.data.data.data;
                    this.pagedata.total = res.data.data.totalSize;
                    }).catch(e => {
                    this.buttonLoading =false;
                    this.$Message.error("数据获取失败")
                })

            },
            formatDate(date, fmt) {
                if (/(y+)/.test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
                }
                let o = {
                    'M+': date.getMonth() + 1,
                    'd+': date.getDate(),
                    'h+': date.getHours(),
                    'm+': date.getMinutes(),
                    's+': date.getSeconds()
                };
                for (let k in o) {
                    if (new RegExp(`(${k})`).test(fmt)) {
                        let str = o[k] + '';
                        fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str));
                    }
                }
                return fmt;
            },
            padLeftZero(str) {
                return ('00' + str).substr(str.length);
            },
            reset() {
                this.form1 = {}
            },
            setOrgId1(data) {
                this.form1.orgId = data[data.length - 1];
            },
            setOrgName1(data) {
                this.form1.orgName = data;
            },
            switchQuery(flag) {
                this.switchFlag = flag;
                if (!this.switchFlag) {
                    this.tableHeight = this.tableHeight + 44;
                } else {
                    this.tableHeight = this.tableHeight - 44;
                }
            },
        }

    }
</script>
